using Super;
using System;
using System.Collections.Generic;
using UnityEngine;

public class UIItemList : MonoBehaviour
{
	// Start is called before the first frame update
	public GameObject itemPrefab;
	private GOPool pool;
	public Dictionary<int, Transform> itemDict = new Dictionary<int, Transform>();

	public void Awake()
	{
		pool = new GOPool(itemPrefab, transform);
	}

	public void SetItemNum(int num, Action<Transform, int> action)
	{
		itemDict.Clear();
		pool.ReturnAll();
		GameObject itemClone;

		for (int i = 0; i < num; i++)
		{
			itemClone = pool.Get();
			itemClone.transform.SetAsLastSibling();

			itemDict[i] = itemClone.transform;
			action(itemClone.transform, i);
		}
		itemPrefab.SetActive(false);
	}

	public Transform GetItemByIndex(int index)
	{
		return itemDict[index];
	}

	public int GetItemCount()
	{
		return itemDict.Count;
	}
}
